package com.web.controller;

import com.domain.system.User;
import org.springframework.web.bind.annotation.ModelAttribute;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class BaseController {

    protected HttpServletRequest request;
    protected HttpServletResponse response;
    protected HttpSession session;

    protected String companyId;
    protected String companyName;

    //登录的User
    protected User loginUser;


    @ModelAttribute
    public void setReqAndResp(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
        this.request = request;
        this.response = response;
        this.session = session;

        //从session域获取User对象,不为null证明登录
        User loginUser = (User) session.getAttribute("loginUser");
        if (loginUser != null) {
            this.companyId = loginUser.getCompanyId();
            this.companyName = loginUser.getCompanyName();
            this.loginUser = loginUser;
        }
    }
}
